package com.scs.application.modules.order.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.scs.application.core.model.CommonResult;
import com.scs.application.core.mvc.controller.BaseBadgeController;
import com.scs.application.core.utils.UserUtils;
import com.scs.application.modules.order.consts.DictConsts;
import com.scs.application.modules.order.entity.PurchaseOrder;
import com.scs.application.modules.order.service.PurchaseOrderService;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 */

@RestController
@RequestMapping({"/order/badges"})
public class OrderBadgeController extends BaseBadgeController {
    @Autowired
    private PurchaseOrderService purchaseOrderService;


    @Override
    public CommonResult<Map<String, Object>> getCount() {
        QueryWrapper<PurchaseOrder> query = Wrappers.query();
        query.eq("status", DictConsts.STATUS_SUPPLIER_UNCONFIRM);
        if (UserUtils.isHospital()) {
            query.eq("hospital_id", UserUtils.getHospitalId());
        }
        if (UserUtils.isSupplier()) {
            query.eq("supplier_id", UserUtils.getSupplierId());
        }
        int waitConfirmOrder = purchaseOrderService.count(query);
        Map<String, Object> map = Maps.newHashMap();
        map.put("waitConfirmOrder", waitConfirmOrder);
        return CommonResult.ok("查询成功", map);
    }
}
